home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / turlvi22.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  5.0 KB  |  213 lines

  1. //    Copyright (c) 1994, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TURLView
  4. //    Include File:    turlview.h
  5. //    Purpose:    Provide a view for a URL.
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        03-24-94    created
  9. #define Uses_TFileDialog
  10. #define Uses_TProgram
  11. #define Uses_TDeskTop
  12. #include"turlview.h"
  13. #include"trace.h"
  14.  
  15. void TURLView::save(const char *cp_filename, const Boolean B_appendff)    {
  16. //    Purpose:    Save the currently viewed document as a text file.
  17. //    Arguments:    cp_filename    The name of the file to save the
  18. //                    view into.
  19. //            B_appendff    Wether or not we should append a
  20. //                    form feed onto the end of the file.
  21. //                    Used in conjunction with printing.
  22. //    Return Value:    void
  23. //    Remarks/Portability/Dependencies/Restrictions:
  24. //        If cp_filename is NULL or is "" then the user will be promted
  25. //        to enter the filename in which to save the view.
  26. //    Revision History:
  27. //        03-24-94    created
  28.  
  29. #ifndef RELEASE
  30.     trace("saving rendered " << cp_filename);
  31. #endif // RELEASE
  32.     auto char *cp_savename = (char *)cp_filename;
  33.  
  34.     //    first, check to see if we need to prompt the user for the
  35.     //    file name.
  36.     if(cp_savename == NULL || *cp_savename == '\0')    {
  37.         //    Create a file dialog box.
  38.         TFileDialog *TFD = new TFileDialog("*.*", "Save Rendering",
  39.             "Save as", fdOKButton, usi_SaveHist);
  40.  
  41.         //    If the dialog was allocated
  42.         if(TFD == NULL)    {
  43.             return;
  44.         }
  45.  
  46.         //    Execute the dialog.
  47.         unsigned short int usi_retval = TProgram::deskTop->
  48.             execView(TFD);
  49.  
  50.         //    If the user didn't cancel.
  51.         if(usi_retval == cmCancel)    {
  52.             destroy(TFD);
  53.             return;
  54.         }
  55.  
  56.         //    Small buffer to hold file name
  57.         auto char ca_buffer[usi_TILURLSize];
  58.  
  59.         //    Get the information from the Dialog
  60.         TFD->getFileName(ca_buffer);
  61.  
  62.         //    Done with the dialog.
  63.         destroy(TFD);
  64.  
  65.         if(NULL == (cp_savename = newStr(ca_buffer)))    {
  66.             return;
  67.         }
  68.     }
  69.  
  70.     //    Remove whitespace from the front of the line.
  71.     if(isspace(*cp_savename))    {
  72.         auto char *cp_temp = cp_savename + 1;
  73.  
  74.         while(isspace(*cp_temp))    {
  75.             cp_temp++;
  76.         }
  77.  
  78.         auto int i_traverse;
  79.         for(i_traverse = 0; *cp_temp != '\0'; i_traverse++)
  80.         {
  81.             *(cp_savename + i_traverse) = *cp_temp++;
  82.         }
  83.  
  84.         *(cp_savename + i_traverse) = '\0';
  85.     }
  86.  
  87.     //    If there is a filename left.
  88.     if(*cp_savename == '\0')    {
  89.         return;
  90.     }
  91.  
  92.  
  93.  
  94.     //    Open the file for writing text.
  95.     auto fstream *fsp_save = new fstream(cp_savename, ios::out |
  96.         ios::trunc);
  97.  
  98.     //    If there was failure, report so.
  99.     if(fsp_save == NULL)    {
  100.         doslynxmessage("Unable to save rendereing to " <<
  101.             cp_savename);
  102.     }
  103.     else    {
  104.         //    We can save.
  105.         //    Seek the rendered image file to the beginning.
  106.         //    Assume it is already open.
  107.         fsp_temp->seekg(0L);
  108.  
  109.         auto Line L_save;
  110.  
  111.         //    While we're not to the end of the file....
  112.         while(fsp_temp->eof() == 0)    {
  113.  
  114.             //    Read the line information.
  115.             fsp_temp->read((char *)(&L_save), sizeof(Line));
  116.             if(fsp_temp->bad() != 0 || fsp_temp->eof() != 0)
  117.             {
  118.                 if(fsp_temp->bad() != 0)    {
  119.                     doslynxmessage("Error in reading "
  120.                         "rendered image " <<
  121.                         TTNp_temp->getName());
  122.                 }
  123.                 break;
  124.             }
  125.  
  126.             //    While we are indenting.
  127.             while(L_save.ssi_indent && L_save.ssi_length != 0)
  128.             {
  129.                 //    Optimize for tabs.
  130.                 if(L_save.ssi_indent >= 8)    {
  131.                     fsp_save->put('\t');
  132.                     L_save.ssi_indent -= 8;
  133.                 }
  134.                 else    {
  135.                     fsp_save->put(' ');
  136.                     L_save.ssi_indent--;
  137.                 }
  138.  
  139.                 if(fsp_save->bad() != 0)    {
  140.                     doslynxmessage("Error in saving "
  141.                     "rendered image " << cp_savename);
  142.                     break;
  143.                 }
  144.             }
  145.  
  146.             //    Continue if all OK.
  147.             if(fsp_save->bad() != 0)    {
  148.                 break;
  149.             }
  150.  
  151.             //    While there is length still in the line.
  152.             while(L_save.ssi_length--)    {
  153.                 //    Output the characters.
  154.                 fsp_save->put(fsp_temp->get());
  155.  
  156.                 //    Check errors.
  157.                 if(fsp_save->bad() != 0)    {
  158.                     doslynxmessage("Error in saving "
  159.                     "rendered image " << cp_savename);
  160.                     break;
  161.                 }
  162.                 else if(fsp_temp->bad() != 0 || fsp_temp->
  163.                     eof() != 0)    {
  164.                     if(fsp_temp->bad() != 0)    {
  165.                         doslynxmessage("Error in "
  166.                             "reading rendered "
  167.                             "image " <<
  168.                             TTNp_temp->getName());
  169.                     }
  170.                     break;
  171.                 }
  172.             }
  173.  
  174.             //    Continue if all OK.
  175.             if(fsp_save->bad() != 0 || fsp_temp->bad() != 0 ||
  176.                 fsp_temp->eof() != 0)
  177.             {
  178.                 break;
  179.             }
  180.  
  181.             //    Output the end of a line.
  182.             fsp_save->put('\n');
  183.             if(fsp_save->bad() != 0)    {
  184.                 doslynxmessage("Error in saving "
  185.                 "rendered image " << cp_savename);
  186.                 break;
  187.             }
  188.         }
  189.  
  190.         //    If we should append a form feed, do so now.
  191.         if(B_appendff == True && fsp_save->bad() == 0)    {
  192.             fsp_save->put('\f');
  193.             if(fsp_save->bad() != 0)    {
  194.                 doslynxmessage("Error in saving "
  195.                 "rendered image " << cp_savename);
  196.             }
  197.         }
  198.  
  199.         //    Close the saved file.
  200.         fsp_save->close();
  201.         delete(fsp_save);
  202.  
  203.         //    Reset the rendered image file to not EOF.
  204.         fsp_temp->clear();
  205.     }
  206.  
  207.  
  208.     //    If we have allocated the space for the file name, then we
  209.     //    need to free it.
  210.     if(cp_savename != cp_filename)    {
  211.         delete(cp_savename);
  212.     }
  213. }